import 'package:flutter/material.dart';

typedef TapAlertActionCallback = bool Function(AlertAction alertAction);

class AlertAction {
  static const int none = 0;
  static const int cancel = 0;
  static const int ok = 100;
  static const int destructive = -1000;

  static final Map<int, String> titlesMap = Map();

  static String actionTitle(int actionTag) {
    String? title = titlesMap[actionTag];
    if (title == null) {
      if (actionTag == cancel) {
        title = '取消';
      } else if (actionTag == ok) {
        title = '确定';
      } else if (actionTag == destructive) {
        assert(() {
          title = '未设置destructive标题';
          return true;
        }());
      }
    }
    return title ?? ' ';
  }

  AlertAction({String? title, required this.tag}) {
    this._title = title;
  }

  final int tag;
  String? _title;

  String get title {
    return _title ?? actionTitle(this.tag);
  }
}

class AlertActionStyle {
  AlertActionStyle({this.textStyle, this.color});

  final TextStyle? textStyle;
  final Color? color;

  static AlertActionStyle cancelStyle =
      AlertActionStyle(textStyle: TextStyle(color: Colors.grey));
  static AlertActionStyle defaultStyle = AlertActionStyle();
  static AlertActionStyle okStyle = AlertActionStyle();
  static AlertActionStyle destructiveStyle =
      AlertActionStyle(color: Colors.red);
}
